import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";

class InfoBlock extends StatelessWidget {
  final String title;
  final EdgeInsetsGeometry? padding;
  final List<Widget>? actions;
  final List<Widget>? children;
  final Widget? content;

  const InfoBlock({super.key, this.padding, this.actions, this.children, required this.title, this.content});

  @override
  Widget build(BuildContext context) {
    List<Widget> list = [
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(title, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),),
          if (actions != null)
            Row(children: actions!,),
        ],
      ),
      if (content != null) content!,
      if (children != null)
        ...children!,
    ];
    return Container(
      padding: padding ?? const EdgeInsets.symmetric(horizontal: ThemeVars.paddingPage, vertical: 12),
      decoration: const BoxDecoration(
          color: Colors.white
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: List.generate(list.length * 2 - 1, (index) {
          if (index.isOdd) {
            if (index == 1) {
              return const SizedBox(height: 12,);
            }
            return const SizedBox(height: 10,);
          }
          Widget ele = list[index ~/ 2];
          return ele;
        }),
      ),
    );
  }

}